<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;

/**
 * @method static where(string $string, mixed $cate_id)
 * @method static create(array $array)
 * @method static find($id)
 */
class Category extends Model
{
    use HasFactory;
    protected $table = "tb_category";
    protected $primaryKey = "cate_id";
    public const CREATED_AT = "cate_create_time";
    public const UPDATED_AT = "cate_update_time";
    protected $fillable = ["cate_name", "cate_parent", "cate_create_time", "cate_status", "cate_weight"];

    // the one to many
    public function children(): HasMany
    {
        return $this->hasMany("App\Models\Category", "cate_parent", "cate_id");
    }

    public function posts(): HasMany
    {
        return $this->hasMany("App\Models\Post", "cate_id", "cate_id");
    }
}
